package br.com.conciliador.util.negocio;

import java.util.HashMap;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.Session;

import br.com.conciliador.util.vo.DominioVo;
import br.com.conciliador.util.hibernate.business.R2HbNgc;
import br.com.r2.util.hibernate.business.RestritorHb;

@SuppressWarnings("unchecked")
public class DominioNgc extends R2HbNgc<DominioVo>
{
	private Map filtroPropriedade = new HashMap();
	private Map restritores = new HashMap();
	
	private static DominioNgc instancia = null;
	
	public static final int JOIN_USUARIOINCLUSAO = 1;
	public static final int JOIN_USUARIOALTERACAO = 2;
	
	private DominioNgc()
	{
		addFiltro("flagAtivo", RestritorHb.RESTRITOR_EQ, "flagAtivo");
		addFiltro("nomeCampo", RestritorHb.RESTRITOR_EQ, "nomeCampo");
	}
	
	public static DominioNgc getInstancia()
	{
		if (instancia == null)
		{
			instancia = new DominioNgc();
		}
		return instancia;
	}

	@Override
	protected Map filtroPropriedade()
	{
		return filtroPropriedade;
	}

	@Override
	protected Criteria montaCriteria(Session sessao, int join)
	{
		Criteria criteria = sessao.createCriteria(DominioVo.class);
		if ((join & JOIN_USUARIOINCLUSAO) != 0)
		{
			criteria.createCriteria("usuarioInclusaoVo", "usuarioInclusao", Criteria.INNER_JOIN);
		}
		if ((join & JOIN_USUARIOALTERACAO) != 0)
		{
			criteria.createCriteria("usuarioAlteracaoVo", "usuarioAlteracao", Criteria.LEFT_JOIN);
		}
		return criteria;
	}

	@Override
	protected Map restritores()
	{
		return restritores;
	}

}
